package com.aaa.web.controller.noticemanage;


import com.aaa.entity.Notice;
import com.aaa.web.commons.NoticeQuery;
import com.aaa.web.commons.Result;
import com.aaa.web.service.noticeservice.WebNoticeService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;
import java.util.Map;

/**
* @description: 后台公告Controller层
* @author: 王林林
* @create: 2018/12/20 10:08
**/
@Controller
@RequestMapping("/webnotice")
public class WebNoticeController {



    @Autowired
    private WebNoticeService service;

    /**
     * 点击公告查询跳转到aiinotice.html
     * */
    @RequestMapping("/getAllNoticePage")
    public String getAllNoticePage(){
        return "views/webhtml/notice/allnotice";
    }

    /**
     * 获取所有公告或按条件查询公告
     * */
    @RequestMapping("/getAllNotice")
    @ResponseBody
    public Map getAllNotice(NoticeQuery query) {
        Map m = service.getAllNotice(query);
        return m;
    }

    /**
     * 根据当前的noticeId删除广告
     **/
    @RequestMapping("/delNoticeById")
    @ResponseBody
    public Result getAllNotice(Integer noticeId) {
        return service.delNoticeById(noticeId);
    }

    /**将图片上传到服务器*/
    @RequestMapping("/uploadPhoto")
    @ResponseBody
    public Map uploadPhoto(@Param("file") MultipartFile file) throws  Exception{
         return service.uploadPhoto(file);
    }


    /**添加或修改广告信息*/
    @RequestMapping("/addOrUpdateNotice")
    @ResponseBody
    public Result addOrUpdateNotice(Notice notice) {
        return service.addOrUpdateNotice(notice);
    }

}
